import { defineStore } from 'pinia'
import { ref } from 'vue'

// 定义 Store
export const configWebsitStore = defineStore(
  'configWebsit',
  () => {
    // 用户信息
    const shopConfig = ref('')
    const serviceConfig = ref('')
    const lifeConfig = ref('')

    const setShop = (val : any) => {
      shopConfig.value = val
    }
    const setService = (val : any) => {
      serviceConfig.value = val
    }
    const setLife = (val : any) => {
      lifeConfig.value = val
    }

    return {
      shopConfig,
      serviceConfig,
      lifeConfig,
      setShop,
      setService,
      setLife
    }
  },
  {
    // 配置持久化
    persist: {
      // 调整为兼容多端的API
      storage: {
        setItem(key : any, value : any) {
          uni.setStorageSync(key, value)
        },
        getItem(key : any) {
          return uni.getStorageSync(key)
        }
      }
    }
  }
)
